#include <iostream>
#include <pthread.h>
#include <ctime>
// 系统调用
#include <sys/types.h>
#include <unistd.h>

void *start_routine(void *argments)
{
    while (true)
    {
        sleep(1);
        std::cout << "new thread running..., pid:" << getpid() << std::endl; // pid就是主线程LWP
        int x = rand() % 5;
        if (x == 0)
            int a = 1/x;
    }
}

int main()
{
    srand(time(nullptr));
    pthread_t tid1; // 存放线程唯一标识
    pthread_create(&tid1, nullptr, start_routine, (void *)"thread_new");
    pthread_t tid2;
    pthread_create(&tid1, nullptr, start_routine, (void *)"thread_new");
    pthread_t tid3;
    pthread_create(&tid1, nullptr, start_routine, (void *)"thread_new");

    while (true)
    {
        std::cout << "main thread running..., pid:" << getpid() << std::endl; // pid就是主线程LWP
        sleep(1);
    }

    return 0;
}
